package xmlcollabserver;
import java.io.*;
import java.net.Socket;
import java.util.List;
/**
 *
 * @author Sasa
 */
public class Requests implements Runnable {
    private Socket client;
    private DataBase db;

    public Requests(Socket client, DataBase db) {
        this.client = client;
        this.db = db;
        //this.start();
        //komentar
    }

    public void run() {
        try { proccesRequest(); }
        catch (Exception e) { System.out.println(e); }
    }

    private void proccesRequest() throws Exception {
        /* input & output */
        InputStream is = client.getInputStream();
       // DataOutputStream os = new DataOutputStream(client.getOutputStream());

        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String line;

        while((line = br.readLine()) != null) {
            //System.out.println(line);
            if(line.equals("USERS")) {
                List<Client> clients = db.getAllClients();
                for(Integer i=0; i< clients.size(); i++) {
                    System.out.println("ID:"+ clients.get(i).id + " " +clients.get(i).username);
                }
            }
            else if(line.equals("TASKS1")) {
                List<Task> tasks = db.getAllTasks(1);
                for(Integer i=0; i< tasks.size(); i++) {
                    System.out.println("Zadatak:"+ tasks.get(i).assigment);
                }
            } else {
                System.out.println(line);
            }
        }
    }
}